package com.itheima.reggie.common;

import java.io.*;
import java.util.List;


//TODO  集合基于对象流的深度拷贝


public class DeepCopy {


    public static <T> List<T> deepCopyList(List<T> source) throws IOException, ClassNotFoundException {
        List<T> target;
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(source);

        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
        target = (List<T>) objectInputStream.readObject();
        return  target;
    }
}